package com.dream.springmvc.filter;

import com.dream.springmvc.filter.operators.*;
import com.dream.springmvc.value.*;
import com.dream.springmvc.value.Value;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Objects;

/**
 * @author panwen
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class DatetimeFilter extends FilterBase<DatetimeValue> {
    private DatetimeValue secondVal;
    private DatetimeOperator op;

    @Override
    protected boolean supports(Value<?> value) {
        return value instanceof DatetimeValue;
    }

    @Override
    protected boolean doMeet(DatetimeValue other) {
        if (Objects.requireNonNull(op) == DatetimeOperator.range) {
            return op.getRangeOpf().eval(getVal().getValue(), secondVal.getValue(), other.getValue());
        }
        return op.getOpf().eval(getVal().getValue(), other.getValue());
    }
}
